﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.Commands;

namespace PloobsEngine.Features
{
    public class PloobsConsoleParametersCommand : ICommand
    {
        private PloobsConsole pc;
        private Dictionary<string, ConsoleVar> vartemp;

        #region ICommand Members

        public PloobsConsoleParametersCommand()
        {
            vartemp = new Dictionary<string, ConsoleVar>();

        }
        public void createVar(string name, ConsoleVar var)
        {

            vartemp.Add(name, var);
        }


        public void setAtribute(string name, float value)
        {
            if (vartemp.ContainsKey(name))
           { 
                if (vartemp[name] is GraphVar)
                {                   
                    ((GraphVar)vartemp[name]).addPoint(value);
                }
                else
                    vartemp[name] = new ConstantVar(value.ToString());
            }
            //else
            //    vartemp.Add(name, value);

        }



        void ICommand.execute()
        {
            //Atualizando os atributos do console
            foreach (KeyValuePair<string, ConsoleVar> item in vartemp)
            {
                pc.UpdateAtribute(item.Key, item.Value);
            }


        }

        public void setTarget(object obj)
        {
            this.pc = obj as PloobsConsole;

        }

        #endregion

        #region ICommand Members


        public string TargetName
        {
            get { return PloobsConsole.MyName; }
        }


        #endregion
    }

}
